<?php


namespace App\Repositories\App;


use App\Models\App\AppProject;
use App\Repositories\BaseRepository;

class AppProjectRepository extends BaseRepository {
    public $eloquentClassName = AppProject::class;
    
    public function getProjectByAppId($appId, $isGetOne = false) {
        return $this->getItemByConditions(
            [
                'wx_authorizer_appid' => $appId
            ],
            null,
            $isGetOne
        );
    }
    
    /**
     * 根据模板id获取项目
     *
     * @param $mptId
     *
     * @return \Illuminate\Database\Eloquent\Collection
     */
    public function getProjectsByMiniProgramTemplateId($mptId, callable $extDealQueryFn = null) {
        return $this->getItemByConditions(
            [
                'mpt_id' => $mptId,
            ],
            $extDealQueryFn
        );
    }
    
    /**
     * @param       $id
     * @param       $applicationId
     * @param array $where
     *
     * @return \App\Commons\Utils\ModelTools\BaseEloquentBuilder|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|null|object
     */
    public function getProjectByIdAndApplicationId($id, $applicationId, $where = []) {
        return AppProjectRepository::getInstance()->getQuery()
            ->where('id', $id)
            ->where('application_id', $applicationId)
            ->where($where)
            ->notDelete()
            ->first();
    }
}